package com.paperobot.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.paperobot.dao.AdminDao;
import com.paperobot.dao.MagazineDao;
import com.paperobot.dao.NewsDao;
import com.paperobot.dao.PaperDao;
import com.paperobot.dao.PaperTypeDao;
import com.paperobot.model.Admin;
import com.paperobot.model.Magazine;
import com.paperobot.model.News;
import com.paperobot.model.Paper;
import com.paperobot.model.PaperType;

@Repository("paperobotService")
public class PaperobotServiceImpl implements PaperobotService{
	
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	
	private NewsDao newsDao;
	private PaperDao  paperDao;
	private AdminDao adminDao;
	private PaperTypeDao paperTypeDao;
	private MagazineDao magazineDao;
	
	@Resource
	public void setNewsDao(NewsDao newsDao) {
		this.newsDao = newsDao;
	}
	@Resource
	public void setPaperDao(PaperDao paperDao) {
		this.paperDao = paperDao;
	}
	@Resource
	public void setAdminDao(AdminDao adminDao) {
		this.adminDao = adminDao;
	}
	@Resource
	public void setPaperTypeDao(PaperTypeDao paperTypeDao) {
		this.paperTypeDao = paperTypeDao;
	}
	@Resource
	public void setMagazineDao(MagazineDao magazineDao) {
		this.magazineDao = magazineDao;
	}
	
	public Long addPaper(Paper paper) {
		try {
			return paperDao.addPaper(paper);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1L;
	}

	public Paper getPaper(Long paperId){
		Paper paper = null;
		try {
			paper = paperDao.getPaper(paperId);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return paper;
	}

	public int updatePaper(Paper paper) {
	
		try {
			return paperDao.updatePaper(paper);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1;
	}
	
	public int updatePaperClickNum(Long paperId) {
		
		try {
			return paperDao.updatePaperClickNum(paperId);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1;
	}

	public int deletePaper(Long paperId) {
		try {
			return paperDao.deletePaper(paperId);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1;
	}
	
	public List<Paper> getPaperList() {
		List<Paper> paperList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		
		try {
			paperList = paperDao.getPaperList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return paperList;
	}
	
	public List<Paper> getPaperList(int type, boolean status) {
		List<Paper> paperList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("type", type);
		map.put("status", status?1:0);
		
		try {
			paperList = paperDao.getPaperList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return paperList;
	}

	public List<Paper> getPaperList(int type, int subType, boolean status) {
		List<Paper> paperList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("type", type);
		map.put("subType", subType);
		map.put("status", status?1:0);
		
		try {
			paperList = paperDao.getPaperList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return paperList;
	}
	public List<Paper> getHotPaperList(int topNum) {
		List<Paper> paperList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("topNum", topNum);
		
		try {
			paperList = paperDao.getHotPaperList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return paperList;
	}

	public List<Paper> getHotPaperList(boolean status, int topNum) {
		List<Paper> paperList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", status?1:0);
		map.put("topNum", topNum);
		
		try {
			paperList = paperDao.getHotPaperList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return paperList;
	}

	public List<Paper> getPaperList(boolean status) {
		List<Paper> paperList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", status?1:0);
		
		try {
			paperList = paperDao.getPaperList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return paperList;
	}

	public List<Paper> getRecommendPaperList(boolean status, int topNum) {
		List<Paper> paperList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", status?1:0);
		map.put("topNum", topNum);
		
		try {
			paperList = paperDao.getRecommendPaperList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return paperList;
	}
	
	public List<Paper> getHotPaperList(int type, boolean status, int topNum) {
		List<Paper> paperList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("type", type);
		map.put("status", status?1:0);
		map.put("topNum", topNum);
		
		try {
			paperList = paperDao.getHotPaperList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return paperList;
	}

	public List<Paper> getHotPaperList(int type, int subType, boolean status, int topNum) {
		List<Paper> paperList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("type", type);
		map.put("subType", subType);
		map.put("status", status?1:0);
		map.put("topNum", topNum);
		
		try {
			paperList = paperDao.getHotPaperList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return paperList;
	}

	public List<Paper> getRecommendPaperList(int topNum) {
		List<Paper> paperList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("topNum", topNum);
		
		try {
			paperList = paperDao.getRecommendPaperList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return paperList;
	}

	public List<Paper> getRecommendPaperList(int type, boolean status, int topNum) {
		List<Paper> paperList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("type", type);
		map.put("status", status?1:0);
		map.put("topNum", topNum);
		
		try {
			paperList = paperDao.getRecommendPaperList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return paperList;
	}

	public List<Paper> getRecommendPaperList(int type, int subType, boolean status, int topNum) {
		List<Paper> paperList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("type", type);
		map.put("subType", subType);
		map.put("status", status?1:0);
		map.put("topNum", topNum);
		
		try {
			paperList = paperDao.getRecommendPaperList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return paperList;
	}
	
	public List<Paper> findPaperList(String title){
		List<Paper> paperList = null;
		
		try {
			paperList = paperDao.findPaperList(title);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return paperList;
	}
	
	public Long addNews(News news) {
		try {
			return newsDao.addNews(news);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1L;
	}

	public News getNews(Long newsId) {
		News News = null;
		try {
			News = newsDao.getNews(newsId);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return News;
	}

	public int deleteNews(Long newsId) {
		try {
			return newsDao.deleteNews(newsId);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1;
	}

	public List<News> getNewsList() {
		List<News> NewsList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		
		try {
			NewsList = newsDao.getNewsList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return NewsList;
	}

	public List<News> getNewsList(boolean status) {
		List<News> NewsList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", status?1:0);
		
		try {
			NewsList = newsDao.getNewsList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return NewsList;
	}
	
	public List<News> getHotNewsList(boolean status, int topNum) {
		List<News> NewsList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", status?1:0);
		map.put("topNum", topNum);
		
		try {
			NewsList = newsDao.getHotNewsList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return NewsList;
	}

	public List<News> getRecommendNewsList(boolean status, int topNum) {
		List<News> NewsList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", status?1:0);
		map.put("topNum", topNum);
		
		try {
			NewsList = newsDao.getRecommendNewsList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return NewsList;
	}

	public int updateNewsClickNum(Long newsId) {
		try {
			return newsDao.updateNewsClickNum(newsId);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1;
	}
	public int updateNews(News news) {
		try {
			return newsDao.updateNews(news);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1;
	}

	public Long addAdmin(Admin admin) {
		try {
			return adminDao.addAdmin(admin);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1L;
	}

	public Admin getAdmin(String userName) {
		Admin admin = null;
		try {
			admin = adminDao.getAdmin(userName);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return admin;
	}
	
	public List<Admin> getAdminList() {
		List<Admin> adminList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		
		try {
			adminList = adminDao.getAdminList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return adminList;
	}
	
	public List<Admin> getAdminList(int type) {
		List<Admin> adminList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("type", type);
		
		try {
			adminList = adminDao.getAdminList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return adminList;
	}

	public List<Admin> getAdminList(int type, boolean status) {
		List<Admin> adminList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("type", type);
		map.put("status", status?1:0);
		
		try {
			adminList = adminDao.getAdminList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return adminList;
	}

	public int updateAdmin(Admin admin) {
		try {
			return adminDao.updateAdmin(admin);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1;
	}
	
	public int deleteAdmin(Long adminId){
		try {
			return adminDao.deleteAdmin(adminId);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1;
	}

	
	
	public Long addPaperType(PaperType paperType) {
		try {
			return paperTypeDao.addPaperType(paperType);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1L;
	}

	public int deletePaperType(Long paperTypeId) {
		try {
			return paperTypeDao.deletePaperType(paperTypeId);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1;
	}

	public PaperType getPaperType(Long paperTypeId) {
		PaperType paperType = null;
		try {
			paperType = paperTypeDao.getPaperType(paperTypeId);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return paperType;
	}

	public List<PaperType> getPaperTypeList() {
		List<PaperType> paperTypeList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		
		try {
			paperTypeList = paperTypeDao.getPaperTypeList(map);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return paperTypeList;
	}

	public List<PaperType> getPaperTypeList(int type) {
		List<PaperType> paperTypeList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("type", type);
		
		try {
			paperTypeList = paperTypeDao.getPaperTypeList(map);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return paperTypeList;
	}

	public int updatePaperType(PaperType paperType) {
		try {
			return paperTypeDao.updatePaperType(paperType);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1;
	}

	public Long addMagazine(Magazine magazine) {
		try {
			return magazineDao.addMagazine(magazine);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1L;
	}

	public int deleteMagazine(Long magazineId) {
		try {
			return magazineDao.deleteMagazine(magazineId);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1;
	}

	public Magazine getMagazine(Long magazineId) {
		Magazine magazine = null;
		try {
			magazine = magazineDao.getMagazine(magazineId);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return magazine;
	}

	public List<Magazine> getMagazineList() {
		List<Magazine> magazineList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		
		try {
			magazineList = magazineDao.getMagazineList(map);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return magazineList;
	}

	public List<Magazine> getMagazineList(boolean status) {
		List<Magazine> magazineList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", status?1:0);
		
		try {
			magazineList = magazineDao.getMagazineList(map);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return magazineList;
	}

	public int updateMagazine(Magazine magazine) {
		try {
			return magazineDao.updateMagazine(magazine);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1;
	}




	
	
}












